<?php
//echo "LIST";
		require_once( "../config/config.php" );
		require_once( "../db/dbconnect.class.php" );
		require_once( "../db/dbGroup.class.php" );
		$DB = new DbGroup();
		
		$sector = $_GET['categoryId'];
		
		$lobSector = $_GET['sector'];
		
		
		
		
		

		
		$sql = "Select * FROM `categories_group` WHERE `id` = '".$sector."';";
		
	//	$html .= "<ul>";
		//$html .= "<select name=\"usergroup\" size=\"\" id=\"usergroup\">";
		
		$result = $DB->selectQuery($sql);
		while ($categories = mysql_fetch_array($result)){
				
			$sql = "Select * FROM `users_group` WHERE `groupId` = '".$categories['id']."' ORDER BY `groupId` DESC;";
			$userresult = $DB->selectQuery($sql);
			$usersInGroupArray = array();
			while($usersInGroup = mysql_fetch_assoc($userresult)){
				array_push($usersInGroupArray, $usersInGroup['userId']);
			}
			
			//$html .= "<p><label for=\"".$users['userId']."\">".$users['userId']."<input type=\"checkbox\" id=\"".$users['userId']."\" name=\"".$users['userId']."\" value=\"".$users['userId']."\"></label></p>";
			$sql = "SELECT `nameOfSector` FROM `sectors` WHERE `id` = '".$_GET['sector']."';";
			$res = $DB->selectQuery($sql);
			$rsArray = mysql_fetch_array($res);
			$lob = $rsArray['nameOfSector'];
			
			
			$sql = "SELECT user_login.*, user_profile.lob FROM user_login JOIN user_profile ON (user_login.id = user_profile.loginId AND user_profile.lob = '".$lob."' AND user_profile.lob IS NOT NULL );";
			
			
			//$sql = "Select * FROM `user_login` ORDER BY `username` ASC;";
			$userresult = $DB->selectQuery($sql);
			$allUsers = array();
			while($allInGroup = mysql_fetch_assoc($userresult)){
				array_push($allUsers, $allInGroup['username']);
			}
			
			//$usersTxt .= "<p><label for=\"".$users['username']."\">".$users['username']."<input type=\"checkbox\" id=\"".$users['username']."\" name=\"".$users['username']."\" value=\"".$users['username']."\"></label></p>";
			
			// remove the elements who's values are in usersInGroup
			//$users = array_diff($users, $usersInGroup);
			
			// reindex the array
			// $users = array_values($users);
			$usersInGroupTxt .= "<h4>Users In Group</h4>";
			foreach($usersInGroupArray as $val){
			$usersInGroupTxt .= "<p onmousedown=\"moveusergroup('".$val."', 'out', '".$categories['id']."');\"><label for=\"".$val."\">".$val."</label></p>";
			}
			
			// remove the elements who's values are in usersInGroup
			$allUsers = array_diff($allUsers, $usersInGroupArray);
			
			// reindex the array
			$allUsers = array_values($allUsers);
			$usersTxt .= "<h4>Users Not In Group</h4>";
			foreach($allUsers as $val){
			
			$usersTxt .= "<p onmousedown=\"moveusergroup('".$val."', 'in', '".$categories['id']."');\"><label for=\"".$val."\">".$val."</label></p>";
			}
			/*
			foreach($users as $key){
			$usersTxt .= "<p><label for=\"".$key['userId']."\">".$key['userId']."<input type=\"checkbox\" id=\"".$users['userId']."\" name=\"".$key['userId']."\" value=\"".$key['userId']."\"></label></p>";
			}
		*/
			
		
		}
		//$html .= "</select>";
		//var_dump($usersInGroupArray);
		echo $usersInGroupTxt."[brk]".$usersTxt;
		///echo $sector;
?>